﻿using Daq.Views;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Telerik.Windows.Controls;

namespace Daq.Services
{
    public interface IDialogService
    {
        Task ShowMessageAsync(string title, string message);
        Task<bool> ShowConfirmationAsync(string title, string message);
        Task<string> ShowInputDialogAsync(string title, string message);
        Task<bool> ShowEditIpDialogAsync(string model, string sn, string ip, string gateway);
    }

    public class DialogService : IDialogService
    {
        public Task ShowMessageAsync(string title, string message)
        {
            RadWindow.Alert(new DialogParameters()
            {
                Header = title,
                Content = message,
                Owner = Application.Current.MainWindow,
            });
            return Task.CompletedTask;
        }

        public Task<bool> ShowConfirmationAsync(string title, string message)
        {
            MessageBoxResult result = MessageBox.Show(message, title,
                MessageBoxButton.YesNo, MessageBoxImage.Question);
            return Task.FromResult(result == MessageBoxResult.Yes);
        }

        public Task<string> ShowInputDialogAsync(string title, string message)
        {
            //// 这里可以实现一个自定义的输入对话框
            //// 为简化示例，我们使用一个简单的解决方案
            //InputDialog inputDialog = new InputDialog(title, message);
            //bool? dialogResult = inputDialog.ShowDialog();

            //if (dialogResult == true)
            //{
            //    return Task.FromResult(inputDialog.InputText);
            //}

            //return Task.FromResult<string>(null);
            return Task.FromResult(string.Empty);
        }

        public Task<bool> ShowEditIpDialogAsync(string model, string sn, string ip, string gateway)
        {
            var view = App.Current.Services.GetService<IpAddressSettingView>();
            if (view == null) return Task.FromResult(false);
            view.Owner = Application.Current.MainWindow;
            view.SetDeviceInfo(model, sn, ip);
            var result = view.ShowDialog();
            return Task.FromResult(result == true);
        }
    }
}
